public class IntegerInputValidator implements InputValidator {

  @Override
  public boolean validate(String inputName, String inputValue,
      Map<String, PropertyValue> properties,
      Messages messages) {
    boolean valid = true;

    if (inputValue != null) {
      Integer value = Integer.parseInt(inputValue);
      // Maximal value.
      {
        Integer max = PropertyUtils.asInteger(properties.get("max"));
        if (max != null && value > max) {
          messages.error(inputName,
              String.format(
                  "Field value can not be more than %1$d", max));
          valid = false;
        }
      }
      // Minimal value.
      {
        Integer min = PropertyUtils.asInteger(properties.get("min"));
        if (min != null && value < min) {
          messages.error(inputName,
              String.format(
                  "Field value can not be less than %1$d", min));
          valid = false;
        }
      }
    }

    return valid;
  }
}
